package com.neoCalf.neoUser.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neoCalf.neoCommon.entity.SysSetting;
import com.neoCalf.neoCommon.redis.RedisTool;
import com.neoCalf.neoCommon.utils.DataTool;
import com.neoCalf.neoUser.mapper.SysSettingMapper;
import com.neoCalf.neoUser.pro.SysSettingPro;
import com.neoCalf.neoUser.service.SysSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.neoCalf.neoCommon.constants.Constants.REDIS_PREFIX_SYS_SETTING;


/**
 * @author 小牛
 * @version 1.0
 * @description TODO
 * @date 2025/4/17 12:43
 */
@Slf4j
@Service(value = "sysSettingServiceImpl")
public class SysSettingServiceImpl extends ServiceImpl<SysSettingMapper, SysSetting> implements SysSettingService {
    @Autowired
    private RedisTool<SysSetting> redisTool;
    @Autowired
    private SysSettingPro sysSettingPro;

    @Override
    public void initSysSetting() {
        SysSetting sysSetting = new SysSetting(
                sysSettingPro.getId(),
                sysSettingPro.getGroupCount(),
                sysSettingPro.getMemberCount(),
                sysSettingPro.getImageSize(),
                sysSettingPro.getVideoSize(),
                sysSettingPro.getFileSize(),
                sysSettingPro.getRobotUid(),
                sysSettingPro.getRobotNick(),
                sysSettingPro.getRobotWelcome()
        );
        boolean b = saveOrUpdate(sysSetting);
        if (!b) {
            throw new RuntimeException("--系统设置初始化失败--");
        }
        redisTool.set(REDIS_PREFIX_SYS_SETTING, sysSetting);
        log.info("--系统设置初始化成功--");
    }
}
